package com.luanye.enjoy.utils;

import com.luanye.enjoy.entity.WeChatUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityUtils
{

    /**
     * 获取用户
     **/
    public static WeChatUser getWeChatUser()
    {
        return (WeChatUser) getAuthentication().getPrincipal();
    }

    /**
     * 获取Authentication
     */
    public static Authentication getAuthentication() {
        return SecurityContextHolder.getContext().getAuthentication();
    }

    public static Boolean isAdmin(){
        Long id = getWeChatUser().getUser().getId();
        return id != null && 1L == id;
    }

    public static Long getUserId() {
        return getWeChatUser().getUser().getId();
    }
}